//
//  LoginViewController.m
//  Nschedule
//
//  Created by 이동민 on 13. 2. 15..
//  Copyright (c) 2013년 이동민. All rights reserved.
//

#import "LoginViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    _MailText.delegate=self;
    _PasswordText.delegate=self;
    
    //키보드가 나오는 노티피케이션 등록
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow) name:
     UIKeyboardDidShowNotification object:nil];
    
    //키보드가 사라지는 노티피케이션 등록
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardDidHideNotification object:nil];
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
}


//키보드가 나오는 노티피케이션 함수
-(void)keyboardWillShow
{
    //뷰 이동 애니메이션
    [UIView beginAnimations:@"Button_Animation" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationsEnabled:YES];
    
    //뷰,텍스트필드 이동
    _MainImage.frame = CGRectMake(0, -149, _MainImage.frame.size.width, _MainImage.frame.size.height);
    _MailText.frame = CGRectMake(73, 304-149, _MailText.frame.size.width, _MailText.frame.size.height);
    _PasswordText.frame = CGRectMake(73, 338-149, _PasswordText.frame.size.width, _PasswordText.frame.size.height);

    
    //애니메이션 시작
    [UIView commitAnimations];

}
//키보드가 사라지는 노티피케이션 함수
-(void)keyboardWillHide
{
    //뷰 이동 애니메이션
    [UIView beginAnimations:@"Button_Animation" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationsEnabled:YES];
    
    //뷰,텍스트필드 이동
    _MainImage.frame = CGRectMake(0, 0, _MainImage.frame.size.width, _MainImage.frame.size.height);
    _MailText.frame = CGRectMake(73, 304, _MailText.frame.size.width, _MailText.frame.size.height);
    _PasswordText.frame = CGRectMake(73, 338, _PasswordText.frame.size.width, _PasswordText.frame.size.height);


    //애니메이션 시작
    [UIView commitAnimations];

}


//키보드 리턴키를 터치했을때
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //키패드가 화면에서 사라지게 됩니다.
    [textField resignFirstResponder];
    return YES;
}

//뷰를 터치하면 호출되는 메서드
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //키패트가 화면에서 사라지게 됩니다.
    [_MailText resignFirstResponder];
    [_PasswordText resignFirstResponder];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)LoginButton:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];

}
@end
